package com.dormitory.management.system.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.dormitory.management.system.entity.UserRole;
import com.dormitory.management.system.mapper.UserRoleMapper;
import com.dormitory.management.system.service.UserRoleService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 用户角色关联表 服务实现类
 * </p>
 *
 * @author 
 * @since 2021-12-20
 */
@Service
public class UserRoleServiceImpl extends ServiceImpl<UserRoleMapper, UserRole> implements UserRoleService {

    @Override
    public boolean save(Long userId, Long roleId) {
        UserRole userRole = new UserRole();
        userRole.setRoleId(roleId);
        userRole.setUserId(userId);
        return this.baseMapper.insert(userRole)>0;
    }

    @Override
    public boolean delete(Long userId) {
        return this.baseMapper.delete(new QueryWrapper<UserRole>().eq("user_id",userId))>0;
    }

    @Override
    public boolean update(Long userId, Long roleId) {
        UserRole userRole = new UserRole();
        userRole.setRoleId(roleId);
        userRole.setUserId(userId);
        return this.baseMapper.updateById(userRole)>0;
    }
}
